package com.atguigu.juc.locks;

import java.util.concurrent.TimeUnit;

//标准访问   (synchronized锁的是方法所在的资源类，也就是new的对象：Phone，有且只有一个资源可以进来)
class Phone{
    public synchronized void sengEmail(){
        System.out.println(Thread.currentThread().getName() + "正在发邮件...");
    }
    public synchronized void sengSMS(){
        System.out.println(Thread.currentThread().getName() + "正在发短信...");
    }
}

public class Lock8_1 {
    public static void main(String[] args) {
        Phone phone = new Phone();

        new Thread(()->{phone.sengEmail();},"t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{phone.sengSMS();},"t2").start();
    }
}
